#include<iostream>
#include<concurrent_priority_queue.h>
#include<unordered_map>
using namespace std;


class Solution {
public:
    vector<int> topKFrequent(vector<int>& nums, int k) {
        unordered_map<int, int> hash;
        for (auto digit : nums)
            hash[digit]++;
        std::priority_queue<pair<int, int>> pq;
        for (auto pa : hash) {
            pq.push(make_pair(pa.second, pa.first));
        }
        vector<int> ans;
        for (int i = 0; i < k; i++) {
            pair<int, int> tmp = pq.top();
            ans.push_back(tmp.second);
            pq.pop();
        }
        return ans;
    }
};